home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1997 October / MACPOWER-1997-10.ISO.7z / MACPOWER-1997-10.ISO / AMUG / PROGRAMMING / Mac F2C 1.3.5.sit / Mac F2C 1.3.5 / Mac F2C v1.3.5 Documentation.rsrc / TEXT_133.txt < prev    next >
Text File  |  1997-06-15  |  5KB  |  91 lines

  1. Using Mac F2C Generated Code
  2.  
  3.  
  4. Stand-Alone Programs
  5.  
  6. The C/C++ code produced by Mac F2C has special compile and link requirements.  These are discussed in detail in the chapters focused on using Mac F2C with specific compilers.  However, the general requirements are easily stated (some of these requirements can be relaxed; refer to the compiler-specific chapters):
  7.  
  8. Compile Requirements
  9. 窶「 Most of these only apply to 68K code generation
  10. 窶「 4-byte integers
  11. 窶「 8-byte doubles
  12. 窶「 far code
  13. 窶「 far data
  14.  
  15. Link Requirements
  16. 窶「 All libraries must be chosen compatible with above compiler settings
  17. 窶「 ANSI libraries
  18. 窶「 Math libraries (if not included in the ANSI libraries)
  19. 窶「 Console libraries (for a minimal Macintosh interface)
  20. 窶「 C++ support libraries (for C++ code only)
  21. 窶「 Mac F2C support libraries (libI77 and libF77)
  22. 窶「 F2Cmain.c or F2Cmain.cp
  23.  
  24. The easiest way to use Mac F2C generated code is to create a new project file using one of the Mac F2C project models or stationary (depending on your environment).  Then add the code files generated by Mac F2C to the project and bring everything up-to-date.  You are ready to run:  that窶冱 all there is to it!  
  25.  
  26. Use the 窶廚窶 versions of project stationary to work with C code generated by Mac F2C and the 窶廚++窶 versions of project stationary to work with C++ code generated by Mac F2C.
  27.  
  28. The enclosed AT&T Computing Science Technical Report No. 149 is your compiler and language reference manual.  I encourage you to read it.  
  29.  
  30.  
  31. Subroutines and Functions
  32.  
  33. You can also use Mac F2C to translate individual FORTRAN subroutines and functions and then call them from your own C or C++ code.  The compile and link requirements specified in the above section remain the same, except that instead of linking against F2Cmain.c or F2Cmain.cp, you link against your own C code.  Also, you only need to link against libI77 and libF77 if your FORTRAN code does any I/O or calls any of the FORTRAN intrinsic functions (including exponentiation, the ** operator).
  34.  
  35. If you include either libI77 or libF77, you need to modify your C or C++ code to accomodate the fatal error trapping mechanism used by these libraries.  These libraries use the ANSI longjmp() function to escape out whenever they encounter a fatal run-time error (the best example is an illegal or ill-formed format statement).  For this mechanism to work, your code needs to declare and set a global jump buffer before any calls to code that might call functions in libI77 or libF77 (i.e., before any calls to code translated by Mac F2C).  You can do this very simply as follows:
  36.  
  37. #include <setjmp.h>
  38. #ifdef __cplusplus
  39.     extern "C" {
  40. #endif
  41.  jmp_buf    gRecoverToConsole;
  42. #ifdef __cplusplus
  43.     }
  44. #endif
  45.  
  46. int main()
  47. {
  48.     if ( setjmp(gRecoverToConsole) == 0 )
  49.     {
  50.          /* Your code here, including calls to FORTRAN code */
  51.          /* translated by Mac F2C */
  52.     }
  53.     else
  54.     {
  55.         /* Fatal run-time error in libI77 or libF77 */
  56.         /* Handle appropriately */
  57.     }
  58. }
  59.  
  60. Obviously, you can put this setjmp() wrapper individually around each call to a translated FORTRAN function instead of the entire code as in my example above.  Although wrapping each call is more work, it will help debugging because you will be able to clearly identify the source of any any run-time errors
  61.  
  62.  
  63. Making Mac F2C-generated Code Multitask
  64.  
  65. Functions have been built into the support library libI77 that allow you to make code generated by Mac F2C multitask under the MacOS cooperative multitasking environment.
  66.  
  67. Using Symantec, THINK or Metrowerks:
  68.  
  69. Cooperative multitasking does not happen automatically.  To make FORTRAN code multitask cooperatively, you need to insert calls such as the following into your FORTRAN source code:
  70.  
  71.     CALL DOMULTITASK( N )
  72.  
  73. where N is the number of ticks (60ths of a second) that you are willing to let your program sleep while other programs execute.  
  74.  
  75. If you prefer, you can instead insert the following function calls in the C/C++ code generated by Mac F2C:
  76.  
  77.     DoMultiTask( N );
  78.  
  79. where N is as above.  You can mix and match the two methods if you wish.  However, note that if you modify the generated C code, your modifications will be destroyed if you re-translate the FORTRAN code. 
  80.  
  81. Using MPW:
  82.  
  83. MPW tools created with the F2C for MPW libraries provide cooperative multitasking for your tools.  This has been coupled with the I/O of the library.  You will notice that while your program is performing io the cursor will be a spinning beach ball.  This allows other programs to have some of the CPU and allows your tool to be put in the background.  If you have some computationally intensive code that does not perform I/O you can call the MPW SpinCursor routine explicitly to free up the CPU for other programs.  The documentation for this routine is provided with MPW.  To call it from FORTRAN use the something like this:
  84.  
  85.     CALL SPINCURSOR( N )
  86.  
  87. where N is the increment to an internal counter (see the MPW SpinCursor doucmentation).  You can simply use 1.  You can also use the same subroutine call as for Symantec, THINK, and CodeWarrior, namely:
  88.  
  89.     CALL DOMULTITASK( N )
  90.  
  91. In the MPW case, the call to DOMULTITASK will simply call through to SPINCURSOR.  However, under MPW, N is interpreted as an increment to the internal counter (instead of as the number of ticks your application is willing to sleep).